 package system.train;

import java.util.LinkedList;
import java.util.Queue;
import system.track.Direction;

/**
 * A predetermined route set through the RouteActions object factory. These
 * routes are based on the C requirements.
 * 
 * @author Yasmine K 
 * @version Spring 2009
 */

public class Route
{
    private Queue<RouteActions> queue;
    private Direction direction;
    
    private Route(Queue<RouteActions> queue)
    {
        this.queue = queue;
    }

    /**
     * Creates the predetermined route based on the direction given.
     * @param direction
     * @return Route the route constructed.
     */
    public static Route createRoute(Direction direction)
    {
        Queue<RouteActions> thequeue = new LinkedList<RouteActions>();
        switch(direction)
        {
            case CLOCKWISE:
            {	
	            	// First outer loop
                    //Starting on Block 1
	            	thequeue.offer(RouteActions.REGISTER_SENSORS);
	                thequeue.offer(RouteActions.SET_NEXT_SWITCH_180);
                	thequeue.offer(RouteActions.ACTIVATE_NEXT_BLOCK);
                	thequeue.offer(RouteActions.ACTIVATE_CURRENT_BLOCK);
                	thequeue.offer(RouteActions.WAIT_FOR_SENSOR);

                    // ON BLOCK 2
                	thequeue.offer(RouteActions.UNREGISTER_SENSORS);
                	thequeue.offer(RouteActions.DEACTIVATE_PREVIOUS_BLOCK);
                	thequeue.offer(RouteActions.MOVE_TRAIN_AHEAD);
                    thequeue.offer(RouteActions.SET_NEXT_SWITCH_180);
                	thequeue.offer(RouteActions.ACTIVATE_NEXT_BLOCK);
                	thequeue.offer(RouteActions.REGISTER_SENSORS);
                	thequeue.offer(RouteActions.WAIT_FOR_SENSOR);

                    // ON BLOCK 9
                    thequeue.offer(RouteActions.UNREGISTER_SENSORS);
                    thequeue.offer(RouteActions.DEACTIVATE_PREVIOUS_BLOCK);
                	thequeue.offer(RouteActions.MOVE_TRAIN_AHEAD);
                	thequeue.offer(RouteActions.ACTIVATE_NEXT_BLOCK);
                	thequeue.offer(RouteActions.REGISTER_SENSORS);
                	thequeue.offer(RouteActions.WAIT_FOR_SENSOR);
                	
                	// ON BLOCK 8
                    thequeue.offer(RouteActions.UNREGISTER_SENSORS);
                	thequeue.offer(RouteActions.DEACTIVATE_PREVIOUS_BLOCK);
                	thequeue.offer(RouteActions.MOVE_TRAIN_AHEAD);
                    thequeue.offer(RouteActions.SET_NEXT_SWITCH_180);
                	thequeue.offer(RouteActions.ACTIVATE_NEXT_BLOCK);
                	thequeue.offer(RouteActions.REGISTER_SENSORS);
                	thequeue.offer(RouteActions.WAIT_FOR_SENSOR);

                    //SECOND OUTER
                    // ON BLOCK 1
                    thequeue.offer(RouteActions.UNREGISTER_SENSORS);
                	thequeue.offer(RouteActions.DEACTIVATE_PREVIOUS_BLOCK);
                	thequeue.offer(RouteActions.MOVE_TRAIN_AHEAD);
                    thequeue.offer(RouteActions.SET_NEXT_SWITCH_180);
                	thequeue.offer(RouteActions.ACTIVATE_NEXT_BLOCK);
                	thequeue.offer(RouteActions.REGISTER_SENSORS);
                	thequeue.offer(RouteActions.WAIT_FOR_SENSOR);

                    // ON BLOCK 2
                	thequeue.offer(RouteActions.UNREGISTER_SENSORS);
                	thequeue.offer(RouteActions.DEACTIVATE_PREVIOUS_BLOCK);
                	thequeue.offer(RouteActions.MOVE_TRAIN_AHEAD);
                    thequeue.offer(RouteActions.SET_NEXT_SWITCH_180);
                	thequeue.offer(RouteActions.ACTIVATE_NEXT_BLOCK);
                	thequeue.offer(RouteActions.REGISTER_SENSORS);
                	thequeue.offer(RouteActions.WAIT_FOR_SENSOR);

                    // ON BLOCK 9
                    thequeue.offer(RouteActions.UNREGISTER_SENSORS);
                    thequeue.offer(RouteActions.DEACTIVATE_PREVIOUS_BLOCK);
                	thequeue.offer(RouteActions.MOVE_TRAIN_AHEAD);
                	thequeue.offer(RouteActions.ACTIVATE_NEXT_BLOCK);
                	thequeue.offer(RouteActions.REGISTER_SENSORS);
                	thequeue.offer(RouteActions.WAIT_FOR_SENSOR);

                	// ON BLOCK 8
                    thequeue.offer(RouteActions.UNREGISTER_SENSORS);
                	thequeue.offer(RouteActions.DEACTIVATE_PREVIOUS_BLOCK);
                	thequeue.offer(RouteActions.MOVE_TRAIN_AHEAD);
                    thequeue.offer(RouteActions.SET_NEXT_SWITCH_180);
                	thequeue.offer(RouteActions.ACTIVATE_NEXT_BLOCK);
                	thequeue.offer(RouteActions.REGISTER_SENSORS);
                	thequeue.offer(RouteActions.WAIT_FOR_SENSOR);

                    //FIRST INNER LOOP
                    // ON BLOCK 1
                    thequeue.offer(RouteActions.UNREGISTER_SENSORS);
                	thequeue.offer(RouteActions.DEACTIVATE_PREVIOUS_BLOCK);
                	thequeue.offer(RouteActions.MOVE_TRAIN_AHEAD);
                    thequeue.offer(RouteActions.SET_NEXT_SWITCH_180);
                	thequeue.offer(RouteActions.ACTIVATE_NEXT_BLOCK);
                	thequeue.offer(RouteActions.REGISTER_SENSORS);
                	thequeue.offer(RouteActions.WAIT_FOR_SENSOR);

                    // ON BLOCK 2
                	thequeue.offer(RouteActions.UNREGISTER_SENSORS);
                	thequeue.offer(RouteActions.DEACTIVATE_PREVIOUS_BLOCK);
                	thequeue.offer(RouteActions.MOVE_TRAIN_AHEAD);
                    thequeue.offer(RouteActions.SET_NEXT_SWITCH_90);
                    thequeue.offer(RouteActions.ACTIVATE_NEXT_BLOCK);
                	thequeue.offer(RouteActions.REGISTER_SENSORS);
                	thequeue.offer(RouteActions.WAIT_FOR_SENSOR);

                    // ON BLOCK 7
                    thequeue.offer(RouteActions.UNREGISTER_SENSORS);
                	thequeue.offer(RouteActions.DEACTIVATE_PREVIOUS_BLOCK);
                	thequeue.offer(RouteActions.MOVE_TRAIN_AHEAD);
                    thequeue.offer(RouteActions.SET_NEXT_SWITCH_180);
                	thequeue.offer(RouteActions.ACTIVATE_NEXT_BLOCK);
                	thequeue.offer(RouteActions.REGISTER_SENSORS);
                	thequeue.offer(RouteActions.WAIT_FOR_SENSOR);

                    // ON BLOCK 6
                    thequeue.offer(RouteActions.UNREGISTER_SENSORS);
                	thequeue.offer(RouteActions.DEACTIVATE_PREVIOUS_BLOCK);
                	thequeue.offer(RouteActions.MOVE_TRAIN_AHEAD);
                    thequeue.offer(RouteActions.SET_NEXT_SWITCH_90);
                	thequeue.offer(RouteActions.ACTIVATE_NEXT_BLOCK);
                	thequeue.offer(RouteActions.REGISTER_SENSORS);
                	thequeue.offer(RouteActions.WAIT_FOR_SENSOR);

                    // SECOND INNER LOOP
                    // ON BLOCK 1
                    thequeue.offer(RouteActions.UNREGISTER_SENSORS);
                	thequeue.offer(RouteActions.DEACTIVATE_PREVIOUS_BLOCK);
                	thequeue.offer(RouteActions.MOVE_TRAIN_AHEAD);
                    thequeue.offer(RouteActions.SET_NEXT_SWITCH_180);
                	thequeue.offer(RouteActions.ACTIVATE_NEXT_BLOCK);
                	thequeue.offer(RouteActions.REGISTER_SENSORS);
                	thequeue.offer(RouteActions.WAIT_FOR_SENSOR);

                    // ON BLOCK 2
                	thequeue.offer(RouteActions.UNREGISTER_SENSORS);
                	thequeue.offer(RouteActions.DEACTIVATE_PREVIOUS_BLOCK);
                	thequeue.offer(RouteActions.MOVE_TRAIN_AHEAD);
                    thequeue.offer(RouteActions.SET_NEXT_SWITCH_90);
                    thequeue.offer(RouteActions.ACTIVATE_NEXT_BLOCK);
                	thequeue.offer(RouteActions.REGISTER_SENSORS);
                	thequeue.offer(RouteActions.WAIT_FOR_SENSOR);

                    // ON BLOCK 7
                    thequeue.offer(RouteActions.UNREGISTER_SENSORS);
                	thequeue.offer(RouteActions.DEACTIVATE_PREVIOUS_BLOCK);
                	thequeue.offer(RouteActions.MOVE_TRAIN_AHEAD);
                    thequeue.offer(RouteActions.SET_NEXT_SWITCH_180);
                	thequeue.offer(RouteActions.ACTIVATE_NEXT_BLOCK);
                	thequeue.offer(RouteActions.REGISTER_SENSORS);
                	thequeue.offer(RouteActions.WAIT_FOR_SENSOR);

                    // ON BLOCK 6
                    thequeue.offer(RouteActions.UNREGISTER_SENSORS);
                	thequeue.offer(RouteActions.DEACTIVATE_PREVIOUS_BLOCK);
                	thequeue.offer(RouteActions.MOVE_TRAIN_AHEAD);
                    thequeue.offer(RouteActions.SET_NEXT_SWITCH_90);
                	thequeue.offer(RouteActions.ACTIVATE_NEXT_BLOCK);
                	thequeue.offer(RouteActions.REGISTER_SENSORS);
                	thequeue.offer(RouteActions.WAIT_FOR_SENSOR);

                    //CROSSOVER
                    // ON BLOCK 1
                    thequeue.offer(RouteActions.UNREGISTER_SENSORS);
                    thequeue.offer(RouteActions.DEACTIVATE_PREVIOUS_BLOCK);
                    thequeue.offer(RouteActions.MOVE_TRAIN_AHEAD);
                    thequeue.offer(RouteActions.ACTIVATE_CURRENT_BLOCK);
                    thequeue.offer(RouteActions.SET_NEXT_SWITCH_90);
                    thequeue.offer(RouteActions.ACTIVATE_PARKING_BLOCK);
                    thequeue.offer(RouteActions.REGISTER_SENSORS);
                    thequeue.offer(RouteActions.WAIT_FOR_SENSOR);

                    //ON BLOCK 4
                    thequeue.offer(RouteActions.UNREGISTER_SENSORS);
                    thequeue.offer(RouteActions.DEACTIVATE_PREVIOUS_BLOCK);
                    thequeue.offer(RouteActions.MOVE_TRAIN_AHEAD);
                    thequeue.offer(RouteActions.TOGGLE_DIRECTION);
                    thequeue.offer(RouteActions.SET_NEXT_SWITCH_90);
                    thequeue.offer(RouteActions.ACTIVATE_NEXT_BLOCK);
                    thequeue.offer(RouteActions.REGISTER_SENSORS);
                    thequeue.offer(RouteActions.WAIT_FOR_SENSOR);

                    //ON BLOCK 7
                    thequeue.offer(RouteActions.UNREGISTER_SENSORS);
                    thequeue.offer(RouteActions.DEACTIVATE_PREVIOUS_BLOCK);
                    thequeue.offer(RouteActions.MOVE_TRAIN_AHEAD);
                    thequeue.offer(RouteActions.SET_NEXT_SWITCH_90);
                    thequeue.offer(RouteActions.ACTIVATE_NEXT_BLOCK);
                    thequeue.offer(RouteActions.REGISTER_SENSORS);
                    thequeue.offer(RouteActions.WAIT_FOR_SENSOR);

                    //FIRST INNER CCW
                    //ON BLOCK 2
                    thequeue.offer(RouteActions.UNREGISTER_SENSORS);
                    thequeue.offer(RouteActions.DEACTIVATE_PREVIOUS_BLOCK);
                    thequeue.offer(RouteActions.MOVE_TRAIN_AHEAD);
                    thequeue.offer(RouteActions.SET_NEXT_SWITCH_180);
                    thequeue.offer(RouteActions.ACTIVATE_NEXT_BLOCK);
                    thequeue.offer(RouteActions.REGISTER_SENSORS);
                    thequeue.offer(RouteActions.WAIT_FOR_SENSOR);

                    //ON BLOCK 1
                    thequeue.offer(RouteActions.UNREGISTER_SENSORS);
                    thequeue.offer(RouteActions.DEACTIVATE_PREVIOUS_BLOCK);
                    thequeue.offer(RouteActions.MOVE_TRAIN_AHEAD);
                    thequeue.offer(RouteActions.SET_NEXT_SWITCH_90);
                    thequeue.offer(RouteActions.ACTIVATE_NEXT_BLOCK);
                    thequeue.offer(RouteActions.REGISTER_SENSORS);
                    thequeue.offer(RouteActions.WAIT_FOR_SENSOR);

                    //ON BLOCK 6
                    thequeue.offer(RouteActions.UNREGISTER_SENSORS);
                    thequeue.offer(RouteActions.DEACTIVATE_PREVIOUS_BLOCK);
                    thequeue.offer(RouteActions.MOVE_TRAIN_AHEAD);
                    thequeue.offer(RouteActions.SET_NEXT_SWITCH_180);
                    thequeue.offer(RouteActions.ACTIVATE_NEXT_BLOCK);
                    thequeue.offer(RouteActions.REGISTER_SENSORS);
                    thequeue.offer(RouteActions.WAIT_FOR_SENSOR);

                    //ON BLOCK 7
                    thequeue.offer(RouteActions.UNREGISTER_SENSORS);
                    thequeue.offer(RouteActions.DEACTIVATE_PREVIOUS_BLOCK);
                    thequeue.offer(RouteActions.MOVE_TRAIN_AHEAD);
                    thequeue.offer(RouteActions.SET_NEXT_SWITCH_90);
                    thequeue.offer(RouteActions.ACTIVATE_NEXT_BLOCK);
                    thequeue.offer(RouteActions.REGISTER_SENSORS);
                    thequeue.offer(RouteActions.WAIT_FOR_SENSOR);

                    //SECOND INNER CCW
                    //ON BLOCK 2
                    thequeue.offer(RouteActions.UNREGISTER_SENSORS);
                    thequeue.offer(RouteActions.DEACTIVATE_PREVIOUS_BLOCK);
                    thequeue.offer(RouteActions.MOVE_TRAIN_AHEAD);
                    thequeue.offer(RouteActions.SET_NEXT_SWITCH_180);
                    thequeue.offer(RouteActions.ACTIVATE_NEXT_BLOCK);
                    thequeue.offer(RouteActions.REGISTER_SENSORS);
                    thequeue.offer(RouteActions.WAIT_FOR_SENSOR);

                    //ON BLOCK 1
                    thequeue.offer(RouteActions.UNREGISTER_SENSORS);
                    thequeue.offer(RouteActions.DEACTIVATE_PREVIOUS_BLOCK);
                    thequeue.offer(RouteActions.MOVE_TRAIN_AHEAD);
                    thequeue.offer(RouteActions.SET_NEXT_SWITCH_90);
                    thequeue.offer(RouteActions.ACTIVATE_NEXT_BLOCK);
                    thequeue.offer(RouteActions.REGISTER_SENSORS);
                    thequeue.offer(RouteActions.WAIT_FOR_SENSOR);

                    //ON BLOCK 6
                    thequeue.offer(RouteActions.UNREGISTER_SENSORS);
                    thequeue.offer(RouteActions.DEACTIVATE_PREVIOUS_BLOCK);
                    thequeue.offer(RouteActions.MOVE_TRAIN_AHEAD);
                    thequeue.offer(RouteActions.SET_NEXT_SWITCH_180);
                    thequeue.offer(RouteActions.ACTIVATE_NEXT_BLOCK);
                    thequeue.offer(RouteActions.REGISTER_SENSORS);
                    thequeue.offer(RouteActions.WAIT_FOR_SENSOR);

                    //ON BLOCK 7
                    thequeue.offer(RouteActions.UNREGISTER_SENSORS);
                    thequeue.offer(RouteActions.DEACTIVATE_PREVIOUS_BLOCK);
                    thequeue.offer(RouteActions.MOVE_TRAIN_AHEAD);
                    thequeue.offer(RouteActions.SET_NEXT_SWITCH_90);
                    thequeue.offer(RouteActions.ACTIVATE_NEXT_BLOCK);
                    thequeue.offer(RouteActions.REGISTER_SENSORS);
                    thequeue.offer(RouteActions.WAIT_FOR_SENSOR);

                    //FIRST OUTER CCW
                    //ON BLOCK 2
                    thequeue.offer(RouteActions.UNREGISTER_SENSORS);
                    thequeue.offer(RouteActions.DEACTIVATE_PREVIOUS_BLOCK);
                    thequeue.offer(RouteActions.MOVE_TRAIN_AHEAD);
                    thequeue.offer(RouteActions.SET_NEXT_SWITCH_180);
                    thequeue.offer(RouteActions.ACTIVATE_NEXT_BLOCK);
                    thequeue.offer(RouteActions.REGISTER_SENSORS);
                    thequeue.offer(RouteActions.WAIT_FOR_SENSOR);

                    //ON BLOCK 1
                    thequeue.offer(RouteActions.UNREGISTER_SENSORS);
                    thequeue.offer(RouteActions.DEACTIVATE_PREVIOUS_BLOCK);
                    thequeue.offer(RouteActions.MOVE_TRAIN_AHEAD);
                    thequeue.offer(RouteActions.SET_NEXT_SWITCH_180);
                    thequeue.offer(RouteActions.ACTIVATE_NEXT_BLOCK);
                    thequeue.offer(RouteActions.REGISTER_SENSORS);
                    thequeue.offer(RouteActions.WAIT_FOR_SENSOR);

                    //ON BLOCK 8
                    thequeue.offer(RouteActions.UNREGISTER_SENSORS);
                    thequeue.offer(RouteActions.DEACTIVATE_PREVIOUS_BLOCK);
                    thequeue.offer(RouteActions.MOVE_TRAIN_AHEAD);
                    thequeue.offer(RouteActions.ACTIVATE_NEXT_BLOCK);
                    thequeue.offer(RouteActions.REGISTER_SENSORS);
                    thequeue.offer(RouteActions.WAIT_FOR_SENSOR);

                    //ON BLOCK 9
                    thequeue.offer(RouteActions.UNREGISTER_SENSORS);
                    thequeue.offer(RouteActions.DEACTIVATE_PREVIOUS_BLOCK);
                    thequeue.offer(RouteActions.MOVE_TRAIN_AHEAD);
                    thequeue.offer(RouteActions.SET_NEXT_SWITCH_180);
                    thequeue.offer(RouteActions.ACTIVATE_NEXT_BLOCK);
                    thequeue.offer(RouteActions.REGISTER_SENSORS);
                    thequeue.offer(RouteActions.WAIT_FOR_SENSOR);

                    //SECOND OUTER CCW
                    //ON BLOCK 2
                    thequeue.offer(RouteActions.UNREGISTER_SENSORS);
                    thequeue.offer(RouteActions.DEACTIVATE_PREVIOUS_BLOCK);
                    thequeue.offer(RouteActions.MOVE_TRAIN_AHEAD);
                    thequeue.offer(RouteActions.SET_NEXT_SWITCH_180);
                    thequeue.offer(RouteActions.ACTIVATE_NEXT_BLOCK);
                    thequeue.offer(RouteActions.REGISTER_SENSORS);
                    thequeue.offer(RouteActions.WAIT_FOR_SENSOR);

                    //ON BLOCK 1
                    thequeue.offer(RouteActions.UNREGISTER_SENSORS);
                    thequeue.offer(RouteActions.DEACTIVATE_PREVIOUS_BLOCK);
                    thequeue.offer(RouteActions.MOVE_TRAIN_AHEAD);
                    thequeue.offer(RouteActions.SET_NEXT_SWITCH_180);
                    thequeue.offer(RouteActions.ACTIVATE_NEXT_BLOCK);
                    thequeue.offer(RouteActions.REGISTER_SENSORS);
                    thequeue.offer(RouteActions.WAIT_FOR_SENSOR);

                    //ON BLOCK 8
                    thequeue.offer(RouteActions.UNREGISTER_SENSORS);
                    thequeue.offer(RouteActions.DEACTIVATE_PREVIOUS_BLOCK);
                    thequeue.offer(RouteActions.MOVE_TRAIN_AHEAD);
                    thequeue.offer(RouteActions.ACTIVATE_NEXT_BLOCK);
                    thequeue.offer(RouteActions.REGISTER_SENSORS);
                    thequeue.offer(RouteActions.WAIT_FOR_SENSOR);

                    //ON BLOCK 9
                    thequeue.offer(RouteActions.UNREGISTER_SENSORS);
                    thequeue.offer(RouteActions.DEACTIVATE_PREVIOUS_BLOCK);
                    thequeue.offer(RouteActions.MOVE_TRAIN_AHEAD);
                    thequeue.offer(RouteActions.SET_NEXT_SWITCH_180);
                    thequeue.offer(RouteActions.ACTIVATE_NEXT_BLOCK);
                    thequeue.offer(RouteActions.REGISTER_SENSORS);
                    thequeue.offer(RouteActions.WAIT_FOR_SENSOR);

                    //ON BLOCK 2
                    thequeue.offer(RouteActions.UNREGISTER_SENSORS);
                    thequeue.offer(RouteActions.DEACTIVATE_PREVIOUS_BLOCK);
                    thequeue.offer(RouteActions.MOVE_TRAIN_AHEAD);
                    thequeue.offer(RouteActions.SET_NEXT_SWITCH_180);
                    thequeue.offer(RouteActions.ACTIVATE_NEXT_BLOCK);
                    thequeue.offer(RouteActions.REGISTER_SENSORS);
                    thequeue.offer(RouteActions.WAIT_FOR_SENSOR);

                    //on block 1 end
                    thequeue.offer(RouteActions.UNREGISTER_SENSORS);
                    thequeue.offer(RouteActions.DEACTIVATE_PREVIOUS_BLOCK);
                    thequeue.offer(RouteActions.MOVE_TRAIN_AHEAD);
                    thequeue.offer(RouteActions.STOP);
                    thequeue.offer(RouteActions.TOGGLE_DIRECTION);
                return new Route(thequeue);
            }
            case COUNTERCLOCKWISE:
            {
                // First outer loop    
	            	/*thequeue.offer(RouteActions.REGISTER_SENSORS_COUNTERCLOCKWISE);
	                thequeue.offer(RouteActions.SET_SWITCH_COUNTERCLOCKWISE_180);
                	thequeue.offer(RouteActions.ACTIVATE_BLOCK_COUNTERCLOCKWISE);
                	thequeue.offer(RouteActions.WAIT_FOR_SENSOR);
                	thequeue.offer(RouteActions.UNREGISTER_SENSORS_COUNTERCLOCKWISE);
                	
                	thequeue.offer(RouteActions.REGISTER_SENSORS_COUNTERCLOCKWISE);
                	thequeue.offer(RouteActions.SET_SWITCH_COUNTERCLOCKWISE_180);
                	thequeue.offer(RouteActions.ACTIVATE_BLOCK_COUNTERCLOCKWISE);
                	thequeue.offer(RouteActions.WAIT_FOR_SENSOR);
                	thequeue.offer(RouteActions.UNREGISTER_SENSORS_COUNTERCLOCKWISE);
                	
                	thequeue.offer(RouteActions.REGISTER_SENSORS_COUNTERCLOCKWISE);
                	thequeue.offer(RouteActions.WAIT_FOR_SENSOR);
                	thequeue.offer(RouteActions.UNREGISTER_SENSORS_COUNTERCLOCKWISE);
                	thequeue.offer(RouteActions.ACTIVATE_BLOCK_COUNTERCLOCKWISE);
                	
                	thequeue.offer(RouteActions.REGISTER_SENSORS_COUNTERCLOCKWISE);
                	thequeue.offer(RouteActions.SET_SWITCH_COUNTERCLOCKWISE_180);
                	thequeue.offer(RouteActions.WAIT_FOR_SENSOR);
                	thequeue.offer(RouteActions.UNREGISTER_SENSORS_COUNTERCLOCKWISE);
                	thequeue.offer(RouteActions.ACTIVATE_BLOCK_COUNTERCLOCKWISE);
                	
                	// Second outer loop
                	thequeue.offer(RouteActions.REGISTER_SENSORS_COUNTERCLOCKWISE);
	                thequeue.offer(RouteActions.SET_SWITCH_COUNTERCLOCKWISE_180);
                	thequeue.offer(RouteActions.WAIT_FOR_SENSOR);
                	thequeue.offer(RouteActions.UNREGISTER_SENSORS_COUNTERCLOCKWISE);
                	thequeue.offer(RouteActions.ACTIVATE_BLOCK_COUNTERCLOCKWISE);
                	
                	thequeue.offer(RouteActions.REGISTER_SENSORS_COUNTERCLOCKWISE);
                	thequeue.offer(RouteActions.SET_SWITCH_COUNTERCLOCKWISE_180);
                	thequeue.offer(RouteActions.WAIT_FOR_SENSOR);
                	thequeue.offer(RouteActions.UNREGISTER_SENSORS_COUNTERCLOCKWISE);
                	thequeue.offer(RouteActions.ACTIVATE_BLOCK_COUNTERCLOCKWISE);
                	
                	thequeue.offer(RouteActions.REGISTER_SENSORS_COUNTERCLOCKWISE);
                	thequeue.offer(RouteActions.WAIT_FOR_SENSOR);
                	thequeue.offer(RouteActions.UNREGISTER_SENSORS_COUNTERCLOCKWISE);
                	thequeue.offer(RouteActions.ACTIVATE_BLOCK_COUNTERCLOCKWISE);
                	
                	thequeue.offer(RouteActions.REGISTER_SENSORS_COUNTERCLOCKWISE);
                	thequeue.offer(RouteActions.SET_SWITCH_COUNTERCLOCKWISE_180);
                	thequeue.offer(RouteActions.WAIT_FOR_SENSOR);
                	thequeue.offer(RouteActions.UNREGISTER_SENSORS_COUNTERCLOCKWISE);
                	thequeue.offer(RouteActions.ACTIVATE_BLOCK_COUNTERCLOCKWISE);
                	
                	// First inner loop
                	thequeue.offer(RouteActions.REGISTER_SENSORS_COUNTERCLOCKWISE);
                	thequeue.offer(RouteActions.SET_SWITCH_COUNTERCLOCKWISE_180);
                	thequeue.offer(RouteActions.WAIT_FOR_SENSOR);
                	thequeue.offer(RouteActions.UNREGISTER_SENSORS_COUNTERCLOCKWISE);
                	thequeue.offer(RouteActions.ACTIVATE_BLOCK_COUNTERCLOCKWISE);
                	
                	thequeue.offer(RouteActions.REGISTER_SENSORS_COUNTERCLOCKWISE);
                	thequeue.offer(RouteActions.SET_SWITCH_COUNTERCLOCKWISE_90);
                	thequeue.offer(RouteActions.WAIT_FOR_SENSOR);
                	thequeue.offer(RouteActions.UNREGISTER_SENSORS_COUNTERCLOCKWISE);
                	thequeue.offer(RouteActions.ACTIVATE_BLOCK_COUNTERCLOCKWISE);
                	
                	thequeue.offer(RouteActions.REGISTER_SENSORS_COUNTERCLOCKWISE);
                	thequeue.offer(RouteActions.SET_SWITCH_COUNTERCLOCKWISE_180);
                	thequeue.offer(RouteActions.WAIT_FOR_SENSOR);
                	thequeue.offer(RouteActions.UNREGISTER_SENSORS_COUNTERCLOCKWISE);
                	thequeue.offer(RouteActions.ACTIVATE_BLOCK_COUNTERCLOCKWISE);
                	
                	thequeue.offer(RouteActions.REGISTER_SENSORS_COUNTERCLOCKWISE);
                	thequeue.offer(RouteActions.SET_SWITCH_COUNTERCLOCKWISE_90);
                	thequeue.offer(RouteActions.WAIT_FOR_SENSOR);
                	thequeue.offer(RouteActions.UNREGISTER_SENSORS_COUNTERCLOCKWISE);
                	thequeue.offer(RouteActions.ACTIVATE_BLOCK_COUNTERCLOCKWISE);
                	
                	// Second inner loop
                	thequeue.offer(RouteActions.REGISTER_SENSORS_COUNTERCLOCKWISE);
                	thequeue.offer(RouteActions.SET_SWITCH_COUNTERCLOCKWISE_180);
                	thequeue.offer(RouteActions.WAIT_FOR_SENSOR);
                	thequeue.offer(RouteActions.UNREGISTER_SENSORS_COUNTERCLOCKWISE);
                	thequeue.offer(RouteActions.ACTIVATE_BLOCK_COUNTERCLOCKWISE);
                	
                	thequeue.offer(RouteActions.REGISTER_SENSORS_COUNTERCLOCKWISE);
                	thequeue.offer(RouteActions.SET_SWITCH_COUNTERCLOCKWISE_90);
                	thequeue.offer(RouteActions.WAIT_FOR_SENSOR);
                	thequeue.offer(RouteActions.UNREGISTER_SENSORS_COUNTERCLOCKWISE);
                	thequeue.offer(RouteActions.ACTIVATE_BLOCK_COUNTERCLOCKWISE);
                	
                	thequeue.offer(RouteActions.REGISTER_SENSORS_COUNTERCLOCKWISE);
                	thequeue.offer(RouteActions.SET_SWITCH_COUNTERCLOCKWISE_180);
                	thequeue.offer(RouteActions.WAIT_FOR_SENSOR);
                	thequeue.offer(RouteActions.UNREGISTER_SENSORS_COUNTERCLOCKWISE);
                	thequeue.offer(RouteActions.ACTIVATE_BLOCK_COUNTERCLOCKWISE);
                	
                	thequeue.offer(RouteActions.REGISTER_SENSORS_COUNTERCLOCKWISE);
                	thequeue.offer(RouteActions.SET_SWITCH_COUNTERCLOCKWISE_90);
                	thequeue.offer(RouteActions.WAIT_FOR_SENSOR);
                	thequeue.offer(RouteActions.UNREGISTER_SENSORS_COUNTERCLOCKWISE);
                	thequeue.offer(RouteActions.ACTIVATE_BLOCK_COUNTERCLOCKWISE);*/
                return new Route(thequeue);
            }
            default:
                throw new IllegalArgumentException("Bad direction arg.");
        }
    }
    
    public boolean executeNextAction(Train train)
    {
       RouteActions action = queue.poll();
       boolean returnVal = action.executeAction(train);
       queue.offer(action);
       return returnVal;
    }
}
